package com.yuecai.modules.activity_coupon;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuecai.modules.activity_coupon.domain.YcActivityGiveCoupon;
import com.yuecai.modules.activity_coupon.domain.dto.YcActivityGiveCouponDto;
import com.yuecai.modules.activity_coupon.service.impl.YcActivityCouponService;
import com.yuecai.modules.activity_coupon.service.impl.YcActivityGiveCouponService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dm
 * @since 2021-01-28
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/activity-coupon")
public class YcActivityCouponController {

    private final YcActivityGiveCouponService ycActivityGiveCouponService;


    private final YcActivityCouponService ycActivityCouponService;

    @GetMapping
    @ApiOperation("查询优惠券包")
    public ResponseEntity<Object> query(YcActivityGiveCouponDto dto, Page page){

        return ResponseEntity.ok(ycActivityGiveCouponService.queryActivityGiveCoupon(dto,page));
    }

    @PostMapping
    @ApiOperation("新增优惠券包")
    public ResponseEntity<Object> create(@Validated @RequestBody YcActivityGiveCouponDto resources) throws Exception {
        return ycActivityCouponService.create(resources);
    }

    @PutMapping
    @ApiOperation("修改优惠券包")
    public ResponseEntity<Object> update(@Validated @RequestBody YcActivityGiveCouponDto resources) throws Exception {
        if (resources.getId()==null){
            throw new Exception("ID不能为空！");
        }
        return ycActivityCouponService.updateGive(resources);
    }

    @ApiOperation("删除优惠券包")
    @DeleteMapping
    public ResponseEntity<Object> delete(@RequestBody Long[] ids) {
        ycActivityGiveCouponService.remove(Wrappers.<YcActivityGiveCoupon>
                lambdaQuery().eq(YcActivityGiveCoupon::getId,ids));
        return new ResponseEntity<>(HttpStatus.OK);
    }

}
